package zjut.cocouml.command;

import org.eclipse.gef.commands.Command;

import zjut.cocouml.model.BCanvas;
import zjut.cocouml.model.BClass;
import zjut.cocouml.model.BaseElement;

public class BClassModifyCommand extends Command{
	
	private BClass model;
	
	private String oldAccessAuthrity;
	private String newAccessAuthrity;
	
	private String oldClassName;
	private String newClassName;
	
	private boolean oldIsFinal;
	private boolean newIsFinal;
	
	private boolean oldIsAbstract;
	private boolean newIsAbstract;
	
	
	public boolean canExecute() {
		//System.out.println("BClassModifyCommand ==  +  " + ((BCanvas)model.getParent()).getFiletable().containsKey(newClassName));
		return !((BCanvas)model.getParent()).getFiletable().containsKey(newClassName);
	}
	
	public void execute() {
		this.oldAccessAuthrity = model.getAccessAuthrity();
		this.oldClassName = model.getName();
		this.oldIsFinal = model.isFinal();
		this.oldIsAbstract = model.isAbstract();
		
		model.setName(newClassName);
		model.setAccessAuthrity(newAccessAuthrity);
		model.setFinal(newIsFinal);
		model.setAbstract(newIsAbstract);
		
		this.model.setDisplayName(this.model.getDisplayName());
		((BCanvas)model.getParent()).getFiletable().put(newClassName,this.model);
		((BCanvas)model.getParent()).getFiletable().remove(oldClassName);
		
	}
	public void undo() {
		model.setName(oldClassName);
		model.setAccessAuthrity(oldAccessAuthrity);
		model.setAbstract(oldIsAbstract);
		model.setFinal(oldIsFinal);
		this.model.setDisplayName(model.getDisplayName());
		((BCanvas)model.getParent()).getFiletable().remove(newClassName);
		((BCanvas)model.getParent()).getFiletable().put(oldClassName,model);
	}
	public void setModel(BClass model) {
		this.model = model;
	}

	public void setOldAccessAuthrity(String oldAccessAuthrity) {
		this.oldAccessAuthrity = oldAccessAuthrity;
	}

	public void setNewAccessAuthrity(String newAccessAuthrity) {
		this.newAccessAuthrity = newAccessAuthrity;
	}

	public void setOldClassName(String oldClassName) {
		this.oldClassName = oldClassName;
	}

	public void setNewClassName(String newClassName) {
		this.newClassName = newClassName;
	}

	public void setOldIsFinal(boolean oldIsFinal) {
		this.oldIsFinal = oldIsFinal;
	}

	public void setNewIsFinal(boolean newIsFinal) {
		this.newIsFinal = newIsFinal;
	}

	public void setOldIsAbstract(boolean oldIsAbstract) {
		this.oldIsAbstract = oldIsAbstract;
	}

	public void setNewIsAbstract(boolean newIsAbstract) {
		this.newIsAbstract = newIsAbstract;
	}

	public void setModel(Object model) {
		this.model = (BClass)model;
	}
}
